<template>
  <div style="width:50%;">
    <el-dialog :visible.sync="modelVisible">
    <el-form ref="form" :model="modelTemp" label-width="80px"  >
      <el-form-item label="名称">
        <el-input v-model="modelTemp.name"></el-input>
      </el-form-item>
      <el-form-item label="日期">
          <el-date-picker type="date" placeholder="选择日期" v-model="modelTemp.date" style="width: 100%;"></el-date-picker>
      </el-form-item>
      <el-form-item label="语言">
        <el-input v-model="modelTemp.language"></el-input>
      </el-form-item>
      <el-form-item label="唱片公司">
        <el-input v-model="modelTemp.recordcompany"></el-input>
      </el-form-item>
      <el-form-item label="类型">
        <el-input v-model="modelTemp.type"></el-input>
      </el-form-item>
      <el-form-item label="封面源">
        <el-input v-model="modelTemp.imgurl"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="handleOk" v-show="method==='add'">新增</el-button>
        <el-button type="primary" @click="handleOk" v-show="method==='edit'">更新</el-button>
        <el-button @click="modelVisible=false">取消</el-button>
      </el-form-item>
    </el-form>
    </el-dialog>
  </div>

</template>

<script>
import {addAlbum,editAlbum} from "@/plugins/api";

export default {
  name: "Modal",
  data(){
    return{
      modelTemp:{},
      modelVisible:false,
      method:"",

    }
  },
  methods:{
    edit(record){
      this.modelTemp=Object.assign({}, record);
    },
    add(){
       this.edit();
    },
    handleOk() {
      var _this=this;
      if (this.method === 'add'){
        addAlbum(this.modelTemp).then(function (msg){
          if(msg.code==200){
            _this.$emit("ok");
            _this.modelVisible=false;
            _this.$message.success(msg.msg);
          }else{
            _this.$message.warning(msg.msg);
          }
        })
      }
      else if(this.method === 'edit'){
        editAlbum(this.modelTemp).then(function (msg){
           if(msg.code==200){
             _this.$emit("ok");
             _this.modelVisible=false;
             _this.$message.success(msg.msg);
           }else{
             _this.$message.warning(msg.msg);
           }
        })
      }
    },
    close () {
      this.$refs.form.clearValidate();
      this.$refs.form.resetFields();
      this.$emit("close");
      this.modelVisible= false;
    },
  }
}
</script>

<style scoped>

</style>